package com.itheima.domain;

import java.io.Serializable;

public class Fruit implements Comparable {
    private String id;
    private String name;
    private double price;
    private int amount;

    public Fruit() {
    }

    public Fruit(String id, String name, double price, int amount) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.amount = amount;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    @Override
    public String toString() {
        return "Fruit{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", price=" + price +
                ", amount=" + amount +
                '}';
    }

    @Override
    public int compareTo(Object o) {
        Fruit fruit = (Fruit) o;
        int result = Integer.parseInt(this.id.substring(1)) - Integer.parseInt(fruit.getId().substring(1));
        return result;
    }
}
